from main.models import Favorites

# Add modules to context, where module is
# the first part of url, eg. /news/technology
# has module news.
def addModule(request):
  url = request.get_full_path()

  # If we have GET args, cut them off
  url = url.split('?')[0]

  if url == '/':
    return {'module_name': 'home'}

  elif url == '/news/':
    return {'module_name': 'all_news'}

  else:
    url = url[1:] #Skip first /
    parts = url.split('/')
    modules = " ".join(parts).rstrip()
    return {'module_name': modules}

def addFavorites(request):
  templateData = []

  if request.user.is_authenticated():
    query = Favorites.objects.filter(user_id=request.user.id)
    for elem in query:
      templateData.append(elem)
    if len(templateData) > 6:
      return {'temp_favorites':templateData}

  # Default if not returned yet
  items = ['Business', 'Sport', 'Art', 'Entertainment', 'Technology', 'Fashion', 'Finance']
  for item in items:
    foo = {}
    foo['search'] = item
    templateData.append(foo)

  return {'temp_favorites':templateData}
